import request from '@/utils/request'

// 获取工单列表
export const getWorkOrders = (params) => {
  return request({
    url: '/work-orders',
    method: 'get',
    params
  })
}

// 获取工单详情
export const getWorkOrder = (id) => {
  return request({
    url: `/work-orders/${id}`,
    method: 'get'
  })
}

// 创建工单
export const createWorkOrder = (data) => {
  return request({
    url: '/work-orders',
    method: 'post',
    data
  })
}

// 更新工单
export const updateWorkOrder = (id, data) => {
  return request({
    url: `/work-orders/${id}`,
    method: 'put',
    data
  })
}

// 删除工单
export const deleteWorkOrder = (id) => {
  return request({
    url: `/work-orders/${id}`,
    method: 'delete'
  })
}

// 分配工单
export const assignWorkOrder = (id, assignedTo) => {
  return request({
    url: `/work-orders/${id}/assign`,
    method: 'patch',
    data: { assignedTo }
  })
}

// 更新工单状态
export const updateWorkOrderStatus = (id, status) => {
  return request({
    url: `/work-orders/${id}/status`,
    method: 'patch',
    data: { status }
  })
}

// 添加解决方案
export const addWorkOrderSolution = (id, solution) => {
  return request({
    url: `/work-orders/${id}/solution`,
    method: 'patch',
    data: { solution }
  })
}

// 添加客户反馈
export const addCustomerFeedback = (id, feedback, satisfactionRating) => {
  return request({
    url: `/work-orders/${id}/feedback`,
    method: 'patch',
    data: { 
      customerFeedback: feedback,
      satisfactionRating 
    }
  })
}

// 完成工单
export const completeWorkOrder = (id) => {
  return request({
    url: `/work-orders/${id}/complete`,
    method: 'patch'
  })
}

// 关闭工单
export const closeWorkOrder = (id) => {
  return request({
    url: `/work-orders/${id}/close`,
    method: 'patch'
  })
}

// 获取工单统计信息
export const getWorkOrderStats = (params) => {
  return request({
    url: '/work-orders/stats',
    method: 'get',
    params
  })
}

// 获取我的工单
export const getMyWorkOrders = (params) => {
  return request({
    url: '/work-orders/my',
    method: 'get',
    params
  })
}

/**
 * 获取工单处理记录列表
 * @param {number} id 工单ID
 * @returns {Promise}
 */
export function getWorkOrderSolutions(id) {
  return request({
    url: `/work-orders/${id}/solutions`,
    method: 'get'
  })
}

/**
 * 获取工单状态历史记录
 * @param {number} id 工单ID
 * @returns {Promise}
 */
export function getWorkOrderStatusHistory(id) {
  return request({
    url: `/work-orders/${id}/status-history`,
    method: 'get'
  })
} 